package com.zzs.client.dao.mysql;

import com.zzs.client.entity.mysql.UserDO;
import org.apache.ibatis.annotations.*;

/**
 * @author zzs
 * @date 2025/03/24
 */
@Mapper
public interface UserMapper {
    @Select("select id, password from user where phone = #{phone}")
    UserDO getIdAndPassword(@Param("phone") String phone);

    @Select("select username, avatar, phone from user where id = #{id}")
    UserDO getUserDetail(@Param("id") long id);

    @Select("select id from user where phone = #{phone}")
    Long getIdByPhone(@Param("phone") String phone);

    @Insert("insert into user (id, phone, create_time, update_time) values (#{id}, #{phone}, #{createTime}, #{updateTime})")
    void save(UserDO user);

    @Update("update user set username = #{username}, update_time = #{updateTime} where id = #{id}")
    int updateInfo(UserDO userDO);

    @Select("select phone from user where id = #{id}")
    String getPhone(@Param("id") long id);

    @Update("update user set password = #{password}, update_time = now() where id = #{id}")
    int updatePassword(@Param("id") long id, @Param("password") String password);

    @Update("update user set avatar = #{avatar} where id = #{id}")
    void uploadAvatar(@Param("id") long id, @Param("avatar") String avatar);

    @Update("update user set phone = #{phone} where id = #{userId}")
    void updatePhone(@Param("userId") long userId, @Param("phone") String phone);
}
